Main Tab 1

Column

Column Tab 1

# A tibble: 91,741 × 11
   stop_date stop_time driver_gender driver_age driver_race violation
   <chr>     <time>    <chr>              <dbl> <chr>       <chr>    
 1 1/2/2005  01:55     M                     20 White       Speeding 
 2 1/18/2005 08:15     M                     40 White       Speeding 
 3 1/23/2005 23:15     M                     33 White       Speeding 
 4 2/20/2005 17:15     M                     19 White       Other    
 5 3/14/2005 10:00     F                     21 White       Speeding 
 6 3/23/2005 09:45     M                     23 Black       Equipment
 7 4/1/2005  17:30     M                     36 White       Speeding 
 8 6/6/2005  13:20     F                     19 White       Speeding 
 9 7/13/2005 10:15     M                     35 Black       Speeding 
10 7/13/2005 15:45     M                     35 White       Speeding 
# ℹ 91,731 more rows
# ℹ 5 more variables: search_conducted <lgl>, stop_outcome <chr>,
#   is_arrested <lgl>, stop_duration <chr>, drugs_related_stop <lgl>

Column Tab 2

Column

Row 1

Row 2

Main Tab 2

Column

1. Plotly for R

Plotly is an R package for creating interactive web-based graphs via plotly’s JavaScript graphing library, plotly.js.

The plotly R package serializes ggplot2 figures into Plotly’s universal graph JSON. plotly::ggplotly will crawl the ggplot2 figure, extract and translate all of the attributes of the ggplot2 figure into JSON (the colors, the axes, the chart type, etc), and draw the graph with plotly.js. Furthermore, you have the option of manipulating the Plotly object with the style function.

2. Cutomizing the Layout

Since the ggplotly() function returns a plotly object, we can manipulate that object in the same way that we would manipulate any other plotly object. A simple and useful application of this is to specify interaction modes, like plotly.js’ layout.dragmode for specifying the mode of click+drag events.

Column

Row 1

Row 2


---
title: "Traffic Stops by Police Officers in RI"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
    logo: logo.png
    source_code: embed
    social: menu
---

```{r setup, include=FALSE}
library(flexdashboard)
library(tidyverse)
library(plotly)
library(knitr)
library(DT)
library(shiny)
df <- read_csv("C:/Users/student/Documents/GitHub/MyMATH421/RIdata.csv")

```

```{r}
# Create a ggplot object
p <- df %>% 
  mutate(is_arrested = factor(is_arrested)) %>% 
  ggplot()+ 
  geom_bar(mapping=aes(x=driver_gender, fill=is_arrested), 
           position = 'fill')+
  labs(y='Proportion', fill='Arrested')

p1 <- df %>% 
  mutate(is_arrested = factor(is_arrested)) %>% 
  ggplot()+ 
  geom_density(mapping=aes(x=driver_age, color=is_arrested))+
  facet_wrap(~violation)
```


{.sidebar}
=======================================================================

### 1. Traffic Stops

Traffic stops by police officers in Rhode Island have gotten attention, starting conversations about racial profiling and disparities in law enforcement outcomes. Analyzing the collected data reveals patterns that show potential inequities within the criminal justice system.

Main Tab 1
=======================================================================

Column {data-width=500, .tabset}
-----------------------------------------------------------------------

### Column Tab 1

```{r}
df
```


### Column Tab 2

```{r}
datatable(df, options = list(
  pageLength = 25
))
```


Column {data-width=500}
-----------------------------------------------------------------------

### Row 1

```{r}
df <- drop_na(df, is_arrested)
df <- drop_na(df, driver_gender)
p
```

### Row 2

```{r}
ggplotly(p)
```

{.sidebar}
=======================================================================

### 1. Titanic

The sinking of the Titanic is one of the most infamous shipwrecks in history. While there was some element of luck involved in surviving, it seems some groups of people were more likely to survive than others.


Main Tab 2
=======================================================================

Column {data-width=500}
-----------------------------------------------------------------------

#### 1. Plotly for R

Plotly is an R package for creating interactive web-based graphs via plotly's JavaScript graphing library, plotly.js.

The plotly R package serializes ggplot2 figures into Plotly's universal graph JSON. plotly::ggplotly will crawl the ggplot2 figure, extract and translate all of the attributes of the ggplot2 figure into JSON (the colors, the axes, the chart type, etc), and draw the graph with plotly.js. Furthermore, you have the option of manipulating the Plotly object with the style function.


#### 2. Cutomizing the Layout

Since the ggplotly() function returns a plotly object, we can manipulate that object in the same way that we would manipulate any other plotly object. A simple and useful application of this is to specify interaction modes, like plotly.js' layout.dragmode for specifying the mode of click+drag events.


Column {data-width=500}
-----------------------------------------------------------------------

```{r}
df <- drop_na(df, driver_age) 
df$is_arrested = factor(df$is_arrested)

driverSex <- unique(df$driver_gender)
```


### Row 1

```{r}
renderPlotly({
  p1 <- df %>% 
    filter(driver_gender==input$sex_input) %>% 
    ggplot(aes(x=driver_age, color=is_arrested))+
    geom_density()
  ggplotly(p1)
})

```

### Row 2

```{r}
ggplotly(p1)
```